<template>
  <div class="app-container">
   
    <el-card class="operate-container" shadow="never">
      <i class="el-icon-tickets"></i>
      <span>会员等级</span>
    </el-card>
    <div class="table-container Level-container">
      <el-table ref="adminTable" :data="list" size="mini" style="width: 100%;" v-loading="listLoading" border>
        <el-table-column label="ID" width="60" align="center">
          <template slot-scope="scope">{{ scope.row.id }}</template>
        </el-table-column>
        <el-table-column label="等级" width="120" align="center">
          <template slot-scope="scope">{{ scope.row.level }}</template>
        </el-table-column>
        <!-- <el-table-column label="图标" align="center">
          <template slot-scope="scope">
           <el-image style="width: 50px; " :src="require(`../../../assets/images/l${scope.row.level}.png`)" fit="fill"></el-image>
          </template>
        </el-table-column> -->
        <el-table-column label="会员价格" min-width="160" align="center">
          <template slot-scope="scope">{{ scope.row.price}}</template>
        </el-table-column>
        <el-table-column label="佣金比例" min-width="140" align="center">
          <template slot-scope="scope">{{ (parseFloat(scope.row.rebateRatio) * 100).toFixed(2)  }}%</template>
        </el-table-column>
        <el-table-column label="最小余额" min-width="180" align="center">
          <template slot-scope="scope">{{ formatAmount(scope.row.balanceMin) }}</template>
        </el-table-column>
        <el-table-column label="接单限制" width="180" align="center">
          <template slot-scope="scope">{{ scope.row.orderLimit }}</template>
        </el-table-column>
        <!-- <el-table-column label="提现次数" align="center">
          <template slot-scope="scope">{{ scope.row.withdrawNum }}</template>
        </el-table-column> -->
        <el-table-column label="提现最小金额" min-width="160" align="center">
          <template slot-scope="scope">{{ formatAmount(scope.row.withdrawMin)}}</template>
        </el-table-column>
        <el-table-column label="提现最大金额" min-width="160" align="center">
          <template slot-scope="scope">{{ formatAmount(scope.row.withdrawMax)  }}</template>
        </el-table-column>
        <el-table-column label="注册时间" width="160" align="center">
          <template slot-scope="scope">{{ scope.row.createTime | formatDateTime }}</template>
        </el-table-column>
        <el-table-column label="操作" width="100" align="center">
          <template slot-scope="scope">
            <el-button size="mini" type="text" @click="handleUpdate(scope.row)"
             >编辑</el-button>
            <!-- <el-button size="mini" type="text" @click="handleDelete(scope.row)"
             >删除</el-button> -->
          </template>
        </el-table-column>
      </el-table>
    </div>
    <div class="pagination-container">
      <el-pagination background @size-change="handleSizeChange" @current-change="handleCurrentChange"
        layout="total, sizes,prev, pager, next,jumper" :current-page.sync="listQuery.pageNum"
        :page-size="listQuery.pageSize" :page-sizes="[5, 10, 15, 20]" :total="total">
      </el-pagination>
    </div>

    <!-- 编辑会员等级对话框 -->
    <edit-grade-dialog  v-if="dialogVisible" :row="row" @handle-cancel="dialogVisible=false" @handle-confirm="handleConfirm"></edit-grade-dialog>
  </div>
</template>
<script>
import { getMemberLevelList } from '@/api/member/index';
import { formatDate } from '@/utils/date';
import { formatAmount } from "@/utils/index";
import EditGradeDialog from "./dialogs/edit-grade-dialog.vue";

const defaultListQuery = {
  pageNum: 1,
  pageSize: 10
};
export default {
  components: {
    EditGradeDialog
  },
  data() {
    return {
      listQuery: Object.assign({}, defaultListQuery),
      list: null,
      total: null,
      listLoading: false,
      dialogVisible: false,
      row:{}
    
    }
  },
  created() {
    this.getList();
  },
  filters: {
    formatDateTime(time) {
      if (time == null || time === '') {
        return 'N/A';
      }
      let date = new Date(time);
      return formatDate(date, 'yyyy-MM-dd hh:mm:ss')
    }
  },
  methods: {
    formatAmount,
    handleSizeChange(val) {
      this.listQuery.pageNum = 1;
      this.listQuery.pageSize = val;
      this.getList();
    },
    handleCurrentChange(val) {
      this.listQuery.pageNum = val;
      this.getList();
    },

    handleConfirm() {
      this.getList();
      this.dialogVisible = false;
    },

    handleDelete(row) {
      this.$confirm('是否要删除该会员等级?', '提示', {

        confirmButtonText: '确定',
        cancelButtonText: '取消',
        type: 'warning'
      }).then(() => {
        // deleteAdmin(row.id).then(response => {
        //   this.$message({
        //     type: 'success',
        //     message: '删除成功!'
        //   });
        //   this.getList();
        // });
      });
    },
    handleUpdate(row) {
      this.row=row;
      this.dialogVisible = true;
    },
    getList() {
      this.listLoading = true;
      getMemberLevelList(this.listQuery).then(response => {
        this.listLoading = false;
        this.list = response.data.list;
        this.total = response.data.total;
      });
    },
  }
}
</script>
<style lang="scss">
.Level-container{
  height: calc(100vh - 190px);
  .el-table__body-wrapper{
    height: calc(100vh - 242px);
    overflow: auto;
  }
}
</style>